package cn.csq.springcloudalibaba;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author csq
 * @date 2022/4/9 18:17:33
 */
@EnableDiscoveryClient
@SpringBootApplication
public class NacosConsumerMainApplication {
    public static void main(String[] args) {
        SpringApplication.run(NacosConsumerMainApplication.class,args);
    }


    @RestController
    public class NacosController {

        //@Autowired
        //private LoadBalancerClient loadBalancerClient;

        @Autowired
        private RestTemplate restTemplate;

        @Value("${spring.application.name}")
        private String appName;

        //@GetMapping("/echo/app-name")
        //public String echoAppName() {
        //    ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-provider");
        //    String path = String.format("http://%s:%S/echo/%s", serviceInstance.getHost(), serviceInstance.getPort(), appName);
        //    System.out.println("request path" + path);
        //    return restTemplate.getForObject(path, String.class);
        //}
    }


    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

}
